<template>
	<view>
		<!-- <headers :HTitle="HTitle" :Licon="Licon" :Subicon="Subicon"></headers> -->
		<view class="Model" @click.stop="navToDetailPage(shop.spuId)">
			<image :src="shop.spuImg" mode=""></image>
			<view class="rht">
				<view class="title">{{shop.spuTitle}}</view>
				<view class="tet">{{shop.spuDescription}}</view>
				<view class="car">
					<view class="left">
						<view class="one">¥{{ shop.spuPrice / 100 }}</view>
						<view class="two"><s>¥{{shop.spuOriginalPrice/100}}/{{shop.spuUnit}}</s></view>
					</view>
					<view class="right" @click.stop="addCart(shop)">
						<image src="../../static/index/cart.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="tuijian">
			<view class="gang"></view>
			<view class="">为你推荐</view>
		</view>
		<image @click="gouwucheBtn" class="gouwuche" src="../../static/tab-icon/tab3_2.png" mode=""></image>
		<view class="meate">
			<view class="meateitem" v-for="item in shopList" @click.stop="navToDetailPage(item.spuId)">
				<image :src="item.spuImg" mode=""></image>
				<view class="texe">{{item.spuTitle}}</view>
				<view class="tmp">
					<view class="lef">¥{{ item.spuPrice / 100 }}</view>
					<image src="../../static/index/cart.png" mode="" @click.stop="addCart(item)"></image>
				</view>
			</view>
		</view>

		<view class="Model" v-for="item in list" style="margin-bottom: 20rpx;  margin-top: 0;" @click.stop="navToDetailPage(item.spuId)">
			<image :src="item.spuImg" mode=""></image>
			<view class="rht">
				<view class="title">{{item.spuTitle}}</view>
				<view class="tet" v-if="item.spuDescription!=undefined">{{ item.spuDescription }}</view>
				<view class="car">
					<view class="left">
						<view class="one">¥{{ item.spuPrice / 100 }}</view>
						<view class="two"><s>¥{{item.spuOriginalPrice/100}}</s></view>
					</view>
					<view class="right" @click.stop="addCart(item)">
						<image src="../../static/index/cart.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>

	</view>

	<!-- <image src="" mode=""></image> -->
</template>

<script>
	import headers from '../../components/lerojon-header_nav/header_nav.vue';
	export default {
		data() {
			return {
				finish: false,
				params: {
					pageNo: 1,
					pageSize: 4,
					recommendType: 1
				},
				HTitle: '今日必买',
				Licon: '../../static/lback.png',
				Subicon: '../../static/shopcar.png',
				id: '',
				shop: '',
				shopList: '',
				list: '',
				pageNo: 1,
				pageSize: 4,
				total: 0,
			};
		},
		onLoad(e) {
			this.id = e.id;
		},
		onReachBottom() {
			if(this.finish){
				this.showList()
			}
		},
		onShow() {
			this.showTui()
			this.showList()
		},
		methods: {
			gouwucheBtn() {
				uni.switchTab({
					url: '/pages/cart/cart'
				});

			},
			showList() {
				this.$api.request('recommend', 'getRecommendByStorage', {
					storageId: this.$store.state.storageId,
					...this.params
				}).then(res => {
					uni.hideLoading();
					this.list = [...this.list, ...res.data.items]
					this.finish = res.data.items.length === this.params.pageSize
					this.params.pageNo++
					this.total = res.data.total
				});
			},
			showTui() {
				this.$api
					.request('recommend', 'getRecommendByStorageAndId', {
						storageId: this.$store.state.storageId,
						recommendType: 1,
						id: this.id
					})
					.then(res => {
						uni.hideLoading();
						// console.log(res);
						this.shop = res.data.recommendDTO
						this.shopList = res.data.recommendDTOList
					});
			},
			//详情页
			navToDetailPage(id) {

				uni.navigateTo({
					url: `/pages/product/detail?id=${id}`
				});
			},
			addCart(item) {
				const that = this;
				that.$api
					.request('cart', 'addCartItem', {
						skuId: item.skuId,
						activityId: item.activityId,
						couponId: item.couponId,
						num: 1
					})
					.then(res => {
						that.$api.msg('添加购物车成功');
						var cartNum = this.$store.state.cartNum + 1;
						that.$store.commit('addCart', cartNum);
						uni.setTabBarBadge({
							index: 2,
							text: cartNum + ''
						});
					});
			}
		},
		components: {
			headers
		}
	};
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background-color: #f9f9f9;
	}

	.gouwuche {
		width: 80rpx;
		height: 80rpx;
		border-radius: 100%;
		position: fixed;
		right: 60rpx;
		bottom: 100rpx;
	}

	.meate {
		width: 100%;
		height: 360rpx;
		display: flex;
		align-items: center;
		padding: 24rpx;
		box-sizing: border-box;
		justify-content: space-between;

		.meateitem {
			width: 32%;
			height: 100%;
			background-color: #ffffff;
			padding: 12rpx;
			box-sizing: border-box;
			text-align: center;

			image {
				width: 180rpx;
				height: 180rpx;
			}

			.texe {
				width: 100%;
				text-align: left;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;

				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
			}

			.tmp {
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-between;
				color: #dd3a2f;
				font-size: 36rpx;

				image {
					width: 60rpx;
					height: 60rpx;
				}
			}
		}
	}

	.Model {
		height: 260rpx;
		width: 100%;
		background-color: #ffffff;
		padding: 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;

		// margin-top: 110rpx;
		image {
			width: 160rpx;
			height: 160rpx;
			margin-right: 40rpx;
		}

		.rht {
			flex: 1;

			.title {
				// width: 100%;
				width: 300rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.tet {
				width: 400rpx;
				// width: 100%;
				margin-top: 8rpx;
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.car {
				display: flex;
				margin-top: 28rpx;
				justify-content: space-between;
				align-items: center;

				.left {
					.one {
						font-size: 36rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #dd3a2f;
					}

					.two {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
					}
				}

				.right {
					image {
						width: 60rpx;
						height: 60rpx;
					}
				}
			}
		}
	}

	.tuijian {
		display: flex;
		align-items: center;
		padding-left: 28rpx;
		box-sizing: border-box;
		margin-top: 32rpx;
		margin-bottom: 12rpx;

		font-size: 36rpx;

		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: bold;
		color: #333333;

		.gang {
			margin-right: 16rpx;
			width: 8rpx;
			height: 36rpx;
			background: #36b542;
			border-radius: 4rpx;
		}
	}
</style>
